package com.edu.demo;

import java.util.Scanner;

public class Practice01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请问您选择排序几个数？？");
        int n=scanner.nextInt();
        int[] numbers=new int[n];
        System.out.println("请输入您要排序的数：");
        for (int i = 0; i < n; i++) {
            numbers[i]=scanner.nextInt();
        }
        sort(numbers);
        System.out.println("");
        System.out.println("请问您想要查找第几大的数？");
        int i = scanner.nextInt();
        System.out.println("第"+"大的数是：");
        System.out.println(numbers[i-1]);
    }

    public static void sort(int[] numbers) {
            //冒泡排序算法
            //需进行length-1次冒泡
            for(int i=0;i<numbers.length-1;i++)
            {
                for(int j=0;j<numbers.length-1-i;j++)
                {
                    if(numbers[j]>numbers[j+1])
                    {
                        int temp=numbers[j];
                        numbers[j]=numbers[j+1];
                        numbers[j+1]=temp;
                    }
                }
            }
            System.out.println("从小到大排序后的结果是:");
            for(int i=0;i<numbers.length;i++)
                System.out.print(numbers[i]+" ");
        }
}
